package photogcalc.calculators;

import photogcalc.calc.ManualFlash;
import photogcalc.util.Settings;
import javax.microedition.lcdui.Screen;
import net.sf.microlog.core.Logger;
import net.sf.microlog.core.LoggerFactory;
import photogcalc.ChildFormListener;
import photogcalc.common.ISOValue;

/**
 *
 * @author aokkonen
 */
public class GnController extends CalculatorController implements DofCommandListener {
    private GnView view = null;
    private GnModel model = null;


    Logger logger = LoggerFactory.getLogger(getClass().getName());

    public GnController(ChildFormListener listener, Settings settings) {
        super(listener);

        model = new GnModel(settings);
        view = new GnView(settings, this);

        view.initData(model.getISOs(), model.getFstops());
    }

    public void calculateCommand() {
        logger.debug("calculateCommand");
        calculateGn();
    }

    private void calculateGn() {
        // Calculate needed guide number
        ManualFlash gn = new ManualFlash();

        ISOValue iso = (ISOValue)model.getISOValueByString((String)model.getSettings().get("sensitivity"));
        int val = gn.calculateGuideNumber(
                iso.getASA(),
                Double.parseDouble(model.getSettings().get("distance")),
                Double.parseDouble(model.getSettings().get("aperture")));
        view.setGuideNumber(new Integer(val).toString());

        gn = null;
    }

    public void refreshScreen() {
        view.refresh();
    }

    public String getIconPrefix() {
        return GnView.ICONPREFIX;
    }

    public String getMenuName() {
        return GnView.MENUNAME;
    }
    
    public Screen getScreen() {
        return view.getScreen();
    }
}
